﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System.Xml.Serialization;
using FYP.Profilings;

namespace FYP.TestCases
{
    public class TestCase
    {
        private string _testcaseName = "Unnamed";

        private Game _game;
        private SpriteBatch _spriteBatch;
        private TestCaseManager _parent;

        private DataManager _dataManager;
        private string _dataFileOutput;

        private bool _isFinish;

        /// <summary>
        /// Initializes a new instance of the TestCase class.
        /// </summary>
        public TestCase(Game game, SpriteBatch spriteBatch)
        {
            _game = game;
            _spriteBatch = spriteBatch;
        }

        public virtual void Initialize()
        {
            DataManager = new DataManager(Game);
            DataManager.Name = TestcaseName;
        }

        public virtual void LoadContent()
        {
        }

        public virtual void TestOn(GameTime gameTime)
        {
            Game.Window.Title = TestcaseName;
        }

        public virtual void TestOff(GameTime gameTime)
        {
            IsFinish = false;
        }

        public virtual void Update(GameTime gameTime)
        {
            _dataManager.Update(gameTime);

            // If finished the test and _dataManager still haven't saved yet
            // Save it now
            if (_isFinish && !_dataManager.IsSaved)
            {
                DataManager.Save(DataFileOutput);
                Game.Window.Title += " - Completed!";
            }
        }


        public virtual void Draw(GameTime gameTime)
        {
            _dataManager.Draw(gameTime);
        }

        #region Properties
        public SpriteBatch SpriteBatch
        {
            get { return _spriteBatch; }
            set { _spriteBatch = value; }
        }
        public Game Game
        {
            get { return _game; }
            set { _game = value; }
        }
        public TestCaseManager Parent
        {
            get { return _parent; }
            set { _parent = value; }
        }
        public string TestcaseName
        {
            get { return _testcaseName; }
            set { _testcaseName = value; }
        }
        public bool IsFinish
        {
            get { return _isFinish; }
            set { _isFinish = value; }
        }
        public FYP.Profilings.DataManager DataManager
        {
            get { return _dataManager; }
            set { _dataManager = value; }
        }
        public string DataFileOutput
        {
            get { return _dataFileOutput; }
            set { _dataFileOutput = value; }
        }
        #endregion
    }
}
